<?php
/* SVN FILE: $Id: app_helper.php 7805 2008-10-30 17:30:26Z AD7six $ */
/**
 * Short description for file.
 *
 * This file is application-wide helper file. You can put all
 * application-wide helper-related methods here.
 *
 * PHP versions 4 and 5
 *
 * CakePHP(tm) :  Rapid Development Framework (http://www.cakephp.org)
 * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright     Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
 * @link          http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
 * @package       cake
 * @subpackage    cake.cake
 * @since         CakePHP(tm) v 0.2.9
 * @version       $Revision: 7805 $
 * @modifiedby    $LastChangedBy: AD7six $
 * @lastmodified  $Date: 2008-10-31 01:30:26 +0800 (Fri, 31 Oct 2008) $
 * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
 */
/**
 * This is a placeholder class.
 * Create the same file in app/app_helper.php
 *
 * Add your application-wide methods in the class below, your helpers
 * will inherit them.
 *
 * @package       cake
 * @subpackage    cake.cake
 */
class AppHelper extends Helper {
    
    function converttolongdate($tarikh)
    {
        $bulan = array(
                        '',
                        __('January',true),
                        __('February',true),
                        __('March',true),
                        __('April',true),
                        __('May',true),
                        __('June',true),
                        __('July',true),
                        __('August',true),
                        __('September',true),
                        __('October',true),
                        __('November',true),
                        __('December',true)
                        );
                        
        $tars = explode('/',$tarikh);
        
        $bb = $bulan[intval($tars[1])];
        
        return $tars[0].' '.$bb.' '.$tars[2];
    }
    
    function converttimeam($strtime)
    {
        $masa = strtolower($strtime);
        $masa = str_replace('am',__('am',true),$masa);
        $masa = str_replace('pm',__('pm',true),$masa);
        
        return $masa;
        
    }
    
    function converttoroman($number)
    {
        $romans = array('','(i)','(ii)','(iii)','(iv)','(v)','(vi)','(vii)','(viii)','(ix)','(x)',
                            '(xi)','(xii)','(xiii)','(xiv)','(xv)','(xvi)','(xvii)','(xviii)','(xix)','(xx)');
                            
        return $romans[$number];
    }
    
    function convertnumbertype($number,$type)
    {
        if ($number<=20)
        {
            $romans[] = array('','1','2','3','4','5','6','7','8','9','10',
                                '11','12','13','14','15','16','17','18','19','20');
            $romans[] = array('','a','b','c','d','e','f','g','h','i','j',
                                'k','l','m','n','o','p','q','r','s','t');
            $romans[] = array('','i','ii','iii','iv','v','vi','vii','viii','ix','x',
                                'xi','xii','xiii','xiv','xv','xvi','xvii','xviii','xix','xx');
                                
            return $romans[$type][$number];
        }
        else
            return $number;
    }
    
    
    function replacecellwidth($namelen,$strbody, $maxlen, $totallen)
    {
        //$total = 410;
        $total = $totallen;
        
        $ratio = 360/54;
        $wn2 = ceil($namelen * $ratio);
        
        //if ($wn2>360)
        //  $wn2 = 360;
        
        if ($wn2>$maxlen)
            $wn2 = $maxlen;
            
        $wn1 = $total - $wn2;
        
        $w1 = $wn1 - 5;
        $w2 = $wn2 + 20;
        
        $rep = array($w1,$w2,$wn1,$wn2);
        $pattern = array('/W1/','/W2/','/WN1/','/WN2/');
        
        return preg_replace($pattern,$rep,$strbody);
        
    }
}
?>
